home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 858 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.8 KB  |  70 lines

  1. Path: engnews1.Eng.Sun.COM!usenet
  2. From: clamage@Eng.sun.com (Steve Clamage)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Quick questions
  5. Date: 26 Mar 1996 00:30:02 GMT
  6. Organization: Sun Microsystems Inc.
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <4j7a64$l9i@engnews1.Eng.Sun.COM>
  9. References: <4j5b26$1e7a@mule1.mindspring.com>
  10. Reply-To: clamage@Eng.sun.com
  11. NNTP-Posting-Host: taumet.eng.sun.com
  12. X-Nntp-Posting-Host: taumet.eng.sun.com
  13. Content-Length: 1900
  14. X-Lines: 40
  15.  
  16. In article 1e7a@mule1.mindspring.com, abell@mindspring.com (Andrew Bell) writes:
  17.  
  18. >2) From a previous post on this group, it looks like the standard will
  19. >allow one to define conversion operators for pre-existing, source code
  20. >untouchable data types.  Yes? No? What will this look like? I have the
  21. >May copy of the WP, and don't see any mention of this.
  22.  
  23. I'm not sure I understand what you are asking. If you mean can you define
  24. a conversion operator from a user-defined class to a predefined type
  25. like int or double, then yes, that has long been part of C++.
  26.     class myclass {
  27.     public:
  28.         operator int() { ... }
  29.     };
  30.  
  31. >3) I often write what I call "pure wrapper" classes to give access
  32. >protection and data abstraction to pre-existing data types.  A pure
  33. >wrapper class is a class that adds no member variables or virtual
  34. >member functions to a class/struct that has no virtual functions of
  35. >its own, so their size and alignment should be the same and casting
  36. >between the two should be perfectly safe.  The new standard doesn't
  37. >have any special support (for example, allowing it automatically) for
  38. >this, does it?
  39.  
  40. I assume you mean a class like
  41.     class Short { short val; };
  42. with non-virtual member functions added. You can't assume the size and
  43. alignment of the class will be the same as its only data member, and no,
  44. the standard provides no special support for this special case.
  45.  
  46. Example: It is common for shorts to be aligned on 2-byte boundaries,
  47. but all structured types to require alignment on 4-byte boundaries.
  48. In this case, all struct types would have a size which is a
  49. multiple of 4.  Casting between short* and Short*, or between
  50. short& and Short&, could cause problems.
  51.  
  52. >4) With RTTI, a derived class that doesn't change any virtual member
  53. >funcs or add any properties to a base class still evaluates to a
  54. >different object type, correct?
  55.  
  56. Yes. The typeids of two types compare equal if and only if they are
  57. the same type. Base and derived classes are not ever the same type.
  58.  
  59. ---
  60. Steve Clamage, stephen.clamage@eng.sun.com
  61.  
  62.  
  63.  
  64.  
  65. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  66. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  67. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  68. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  69. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  70.